﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class UpdateProductionTaskCommandHanders : IRequestHandler<UpdateProductionTaskCommands,APIResult<ProductionTask>>
    {
        private readonly IBaseRepository<ProductionTask> _repository;
        private readonly IMapper mapper;

        public UpdateProductionTaskCommandHanders(IBaseRepository<ProductionTask> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加生产任务
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<ProductionTask>> Handle(UpdateProductionTaskCommands request, CancellationToken cancellationToken)
        {
            APIResult<ProductionTask> result = new APIResult<ProductionTask>();
            result.Code = APIEnum.修改成功;
            result.Msg = "修改成功";
            var cao = mapper.Map<ProductionTask>(request);
            var list = "Update ProductionTask set TaskNumber=@TaskNumber,TaskName=@TaskName,WorkStationNumber=@WorkStationNumber,WorkStationName=@WorkStationName,ScheduledNumber=@ScheduledNumber,QuantityProduced=@QuantityProduced,StartofProductionTime=@StartofProductionTime,ProductionTime=@ProductionTime,EstimatedTime=@EstimatedTime,DisplayColor=@DisplayColor,IsDelete=@IsDelete where ProductionTaskId=@ProductionTaskId";
            await _repository.Insert(cao, list);
            return result;
        }
    }
}
